package com.android.support.lib.universal.view.dialog;

import com.android.support.lib.universal.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

/**
 * 自定义弹窗
 * 
 * @author 彭治铭
 *
 */
public class AlertDialog {
	Context context;
	android.app.AlertDialog dialog;
	TextView textView_title;
	TextView textView_message;
	Button button_Positive;
	Button button_Negative;

	@SuppressLint("NewApi")
	/**
	 * 
	 * @param context
	 * @param bool false(按对话框以外的地方不起作用,即不会消失)，true(按其他区域会消失)。按返回键还起作用
	 */
	public AlertDialog(Context context, Boolean bool) {
		super();
		// TODO Auto-generated constructor stub
		this.context = context;
		dialog = new android.app.AlertDialog.Builder(context, R.style.Dialog).create();// R.style.Dialog为布局主题，也可以用0
		dialog.show();
		dialog.setCanceledOnTouchOutside(bool);// 调用这个方法时，按对话框以外的地方不起作用。按返回键还起作用
		Window window = dialog.getWindow();
		window.setContentView(R.layout.lib_alertdialog);// 弹出框的布局
		textView_title = (TextView) window.findViewById(R.id.txt_title);
		textView_message = (TextView) window
				.findViewById(R.id.textView_content);
		button_Negative = (Button) window.findViewById(R.id.button_Negative);
		button_Positive = (Button) window.findViewById(R.id.button_Positive);
	}

	/**
	 * 标题
	 * 
	 * @param title
	 */
	public void setTitle(String title) {
		textView_title.setText(title);
	}

	/**
	 * 信息
	 * 
	 * @param message
	 */
	public void setMessage(String message) {
		textView_message.setText(message);
	}

	/**
	 * 设置按钮 ---取消
	 * 
	 * @param text
	 * @param listener
	 * @param bool
	 *            true字体颜色为主字体颜色 false 字体颜色为次字体颜色
	 */
	public void setNegativeButton(String text,
			final View.OnClickListener listener, Boolean bool) {
		button_Negative.setText(text);
		button_Negative.setOnClickListener(listener);
		if (bool) {
			button_Negative.setTextColor(context.getResources()
					.getColorStateList(R.color.lib_font_main));
		} else {
			button_Negative.setTextColor(context.getResources()
					.getColorStateList(R.color.lib_font_sub));
		}

	}

	/**
	 * 设置按钮---保存
	 * 
	 * @param text
	 * @param listener
	 * @param bool
	 *            true字体颜色为主字体颜色 false 字体颜色为次字体颜色
	 */
	public void setPositiveButton(String text,
			final View.OnClickListener listener, Boolean bool) {
		button_Positive.setText(text);
		button_Positive.setOnClickListener(listener);
		if (bool) {
			button_Positive.setTextColor(context.getResources()
					.getColorStateList(R.color.lib_font_main));
		} else {
			button_Positive.setTextColor(context.getResources()
					.getColorStateList(R.color.lib_font_sub));
		}
	}

	/**
	 * 关闭对话框
	 */
	public void dismiss() {
		dialog.dismiss();
	}

	public void show(){
		dialog.show();
	}
}
